package top.mcwebsite.lib.route.api

import android.os.Bundle
import android.os.Parcelable
import java.io.Serializable

class RouterRequestBuilder(val path: String) {

    private val bundle: Bundle by lazy {
       Bundle()
    }

    fun withByte(key: String, value: Byte) = this.apply {
        bundle.putByte(key, value)
    }

    fun withShort(key: String, value: Short) = this.apply {
        bundle.putShort(key, value)
    }

    fun withInt(key: String, value: Int) = this.apply {
        bundle.putInt(key, value)
    }

    fun withLong(key: String, value: Long) = this.apply {
        bundle.putLong(key, value)
    }

    fun withBoolean(key: String, value: Boolean) = this.apply {
        bundle.putBoolean(key, value)
    }

    fun withChar(key: String, value: Char) = this.apply {
        bundle.putChar(key, value)
    }

    fun withFloat(key: String, value: Float) = this.apply {
        bundle.putFloat(key, value)
    }

    fun withDouble(key: String, value: Double) = this.apply {
        bundle.putDouble(key, value)
    }

    fun withString(key: String, value: String) = this.apply {
        bundle.putString(key, value)
    }

    fun withSerializable(key: String, value: Serializable) = this.apply {
        bundle.putSerializable(key, value)
    }

    fun withParcelableArrayList(key: String, value: ArrayList<out Parcelable>) {
        bundle.putParcelableArrayList(key, value)
    }

    fun withParcelable(key: String, value: Parcelable) = this.apply {
        bundle.putParcelable(key, value)
    }

    fun withBundle(key: String, bundle: Bundle) = this.apply {
        this.bundle.putBundle(key, bundle)
    }

    fun withArgumentAction(action: (Bundle) -> Unit) {
        action(bundle)
    }

    fun build(): RouterRequest {
        return RouterRequest(
            routePath = path,
            params = if (bundle.isEmpty) null else bundle
        )
    }
}